﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CommonFunction;

namespace Pokerist
{
    public partial class RegisterProduct : Form
    {
        public RegisterProduct()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnRegister_Click(object sender, EventArgs e)
        {
            UtilityHelper helper = new UtilityHelper();
            
            if (helper.checkLicense(txtActivationCode.Text, txtActivationKey.Text))
            {
                try
                {
                    StreamWriter writer = new StreamWriter(Path.Combine(Application.StartupPath, @"privsController.dll"));
                    writer.Write(setValue(txtActivationKey.Text));
                    writer.Flush();
                    writer.Close();

                    Pokerist_Common.HasLicensed = true;
                    
                    MessageBox.Show("Thank you for your register. Registation successfully", "Pokerist");
                    this.Close();
                }
                catch
                {
                    MessageBox.Show("Registation fail", "Pokerist");
                }
            }            
        }

        private string setValue(string activationCode)
        {
            activationCode = string.Format("<ActivationKey>{0}</ActivationKey>", activationCode);

            return activationCode;
        }

        private void RegisterProduct_Load(object sender, EventArgs e)
        {
            UtilityHelper helper = new UtilityHelper();
            txtActivationCode.Text = helper.GenerateCode(helper.GetActivateString());
        }
    }
}
